<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
session_start();
$_LangPath = "Account_Bet";
include_once($_SERVER["DOCUMENT_ROOT"]."/getvars.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]."/language/selectlanguage_admin.php");
include_once($_SERVER["DOCUMENT_ROOT"]."/db.inc.php");
/*eregi("<!--account start-->(.*)<!--account end-->",strtolower($_SESSION["Admin_Info"] -> ProgramPower), $arrPOWER);
$isLimit = true;
switch($arrPOWER[1]){
	case "agent-sub":
		include_once($_SERVER["DOCUMENT_ROOT"]."/k_admin/logincheck_agent_report.php");
		$data["SubID_n"] = $_SESSION["Admin_Info"] -> ParentID;
		break;

	case "main-sub":
		include_once($_SERVER["DOCUMENT_ROOT"]."/k_admin/logincheck_mainagent_report.php");
		$data["MainID_n"] = $_SESSION["Admin_Info"] -> ParentID;
		break;

	case "stockholder-sub":
		include_once($_SERVER["DOCUMENT_ROOT"]."/k_admin/logincheck_stock_report.php");
		$data["StockID_n"] = $_SESSION["Admin_Info"] -> ParentID;
		break;

	case "agent":
		include_once($_SERVER["DOCUMENT_ROOT"]."/k_admin/logincheck_agent_report.php");
		$data["SubID_n"] = $_SESSION["Admin_Info"] -> ID;
		break;

	case "main":
		include_once($_SERVER["DOCUMENT_ROOT"]."/k_admin/logincheck_mainagent_report.php");
		$data["MainID_n"] = $_SESSION["Admin_Info"] -> ID;
		break;

	case "stockholder":
		include_once($_SERVER["DOCUMENT_ROOT"]."/k_admin/logincheck_stock_report.php");
		if($_data["WagerType"] != "1"){
			$data["StockID_n"] = $_SESSION["Admin_Info"] -> ID;
		}
		break;

	case "all":
		$isLimit = false;
	case "all-limit":
		include_once($_SERVER["DOCUMENT_ROOT"]."/k_admin/logincheck_op.php");
		break;

	default:
		$title = "Error";
		$GLOBALS["errormessage"] =  $_strAccount_Bet["NoPower"]; //""很抱歉！您沒有此程式的使用權限！";
		include_once($_SERVER["DOCUMENT_ROOT"]."/k_admin/error.php");
		exit();
		break;
}*/

include_once($_SERVER["DOCUMENT_ROOT"]."/modules/SQLUtility.lib.php");
include_once($_SERVER["DOCUMENT_ROOT"]."/common/Lotto.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]."/modules/ChangeTime.lib.php");
include_once($_SERVER["DOCUMENT_ROOT"]."/modules/WagerForm.lib.php");
include_once($_SERVER["DOCUMENT_ROOT"]."/modules/Account.lib.php");
include_once("BetTmp_ListResult.php");

	$fp = @file($_SERVER["DOCUMENT_ROOT"]."/admintemplate/Account/Bet_List.html");
	$fp = join("", $fp);
	$fp = str_replace("{Charset}", $_Charset, $fp);
	$fp = str_replace("{Bet_Type}", $_data["Bet_Type"], $fp);
	$fp = str_replace("{WagerType}", $_data["WagerType"], $fp);
	$fp = str_replace("{LottoID}", $_data["LottoID"], $fp);
	$fp = str_replace("{Types}", $_data["Types"], $fp);
	$fp = str_replace("{PayupDate_0}", $data["PayupDate_x"][0], $fp);
	$fp = str_replace("{PayupDate_1}", $data["PayupDate_x"][1], $fp);
	$fp = str_replace("{GambleID}", $_data["GambleID"], $fp);
	$fp = str_replace("{Number}", $_data["Number"], $fp);
	$fp = str_replace("{SubmitForm}", $strSubmitForm, $fp);
	$fp = str_replace("{Gops}", $_data["ops"], $fp);
	$fp = str_replace("{MemID}", $_data["MemID"], $fp);
	$fp = str_replace("{TotalPage}", $intTotalPage, $fp);
	$fp = str_replace("{PageNow}", $intPageNow, $fp);
	$fp = str_replace("{SubID}", $_data["SubID"], $fp);
	$fp = str_replace("{MainID}", $_data["MainID"], $fp);
	$fp = str_replace("{SelectLotto}", (empty($_data["LottoID"]))?"All":$_arrLotto[$_data["LottoID"]]["Lotto_".$_intLang], $fp);
	$fp = str_replace("{SelectBetType}", (empty($_data["Bet_Type"]))?"All":$_arrBet_Type[$_data["Bet_Type"]], $fp);

	if($_data["ops"] == "Gamble" || $_data["ops"] == "GambleStock"){
		$fp = str_replace("{BackContent}", $_strAccount_Bet["Bet_Back1"], $fp);
		$fp = str_replace("{BackLink}", "JavaScript:history.back()", $fp);
	}elseif(!empty($_data["MainID"])){
		if($_data["Types"] == "Stock"){
			$fp = str_replace("{BackContent}", $_strAccount_Bet["Bet_Back4"], $fp);
			$fp = str_replace("{BackLink}", "Stock_index.php?op=Search", $fp);
		}else{
			$fp = str_replace("{BackContent}", $_strAccount_Bet["Bet_Back2"], $fp);
			$fp = str_replace("{BackLink}", "index.php?op=Search", $fp);
		}
	}else{
		if($_data["Types"] == "Stocks"){
			$fp = str_replace("{BackContent}", $_strAccount_Bet["Bet_Back4"], $fp);
			$fp = str_replace("{BackLink}", "Stock_index.php?op=Search", $fp);
		}else{
			$fp = str_replace("{BackContent}", $_strAccount_Bet["Bet_Back3"], $fp);
			$fp = str_replace("{BackLink}", "Sub_index.php?op=Search", $fp);
		}
	}

	while(list($k, $v) = each($_strAccount_Bet)){
		$fp = str_replace("{".$k."}", $v, $fp);
	}

	//條列式數字 選擇頁數
	ereg("<!--@ LinkPage Start @//-->(.+)<!--@ LinkPage End @//-->", $fp, $d);
	for($i = $firstpage; $i <= $lastpage; $i++){
		if($i == $intPageNow){
			$tmpLink = str_replace("{LinkPageLink}", "", $d[1]);
			$tmpLink = str_replace("{LinkPageClass}", "a_text", $tmpLink);
		}else{
			$tmpLink = str_replace("{LinkPageLink}", "href=\"JavaScript:Page(".$i.");\"", $d[1]);
			$tmpLink = str_replace("{LinkPageClass}", "topbar", $tmpLink);
		}
		$tmpLink = str_replace("{LinkPage}", $i, $tmpLink);
		$strLink .= $tmpLink;
	}
	$fp = ereg_replace("<!--@ LinkPage Start @//-->.+<!--@ LinkPage End @//-->", $strLink, $fp);

	//下拉式選單 選擇頁數
	ereg("<!--@ SelectPage Start @//-->(.+)<!--@ SelectPage End @//-->", $fp, $d);
	for($i = 1; $i <= $intTotalPage; $i++){
		$isSelect = ($i == $intPageNow)?" selected":"";
		$tmpSelect = str_replace("{SelectPage}", $i, $d[1]);
		$strSelect .= str_replace("{Selected}", $isSelect, $tmpSelect);
	}
	$fp = ereg_replace("<!--@ SelectPage Start @//-->.+<!--@ SelectPage End @//-->", $strSelect, $fp);

	//上一頁
	if($intPageNow < 2){
		$fp = ereg_replace("<!--@ PrePage_2 Start @//-->.+<!--@ PrePage_2 End @//-->", "", $fp);
	}else{
		$fp = ereg_replace("<!--@ PrePage_1 Start @//-->.+<!--@ PrePage_1 End @//-->", "", $fp);
		$fp = str_replace("{PrePage}", ($intPageNow - 1), $fp);
	}

	//下一頁
	if($intPageNow >= $intTotalPage){
		$fp = ereg_replace("<!--@ NextPage_2 Start @//-->.+<!--@ NextPage_2 End @//-->", "", $fp);
	}else{
		$fp = ereg_replace("<!--@ NextPage_1 Start @//-->.+<!--@ NextPage_1 End @//-->", "", $fp);
		$fp = str_replace("{NextPage}", ($intPageNow + 1), $fp);
	}


	//下注清單
	ereg("<!--@ BetList Start @//-->(.+)<!--@ BetList End @//-->", $fp, $d);

	$sumtotals = 0;
	$sumMemStake = 0;
	$sumSubIncome = 0;
	$MainID = "";
	if(is_array($arrRows)){
		if(sizeof($arrRows) > 0){
			while(list($k, $Rows)=each($arrRows)){
				$strTmp = "";
				$tmpBetList = str_replace("{Show_BetDate}", DateForm($arrConRows[$k] -> BD, $arrConRows[$k] -> BT), $d[1]);
				$tmpBetList = str_replace("{Show_BetTime}", TimeForm($arrConRows[$k] -> BD, $arrConRows[$k] -> BT), $tmpBetList);
				$tmpBetList = str_replace("{Show_BetNo}", $Rows -> ID, $tmpBetList);
				$tmpBetList = str_replace("{Show_Account}", $arrConRows[$k] -> MemAccount."&nbsp;".(100 - $Rows -> MC*100), $tmpBetList);
				$tmpBetList = str_replace("{Show_BetType}", $_arrBet_Type[$Rows -> Bet_Type].$bb, $tmpBetList);
				$strTmpCon =  WagerFormTrans($Rows -> LottoID, $Rows -> Bet_Type, $arrConRows[$k] -> Content);
				$tmpBetList = str_replace("{Show_Content}", $strTmpCon, $tmpBetList);
				if($Rows -> Bet_Type >= 7 && $Rows -> Bet_Type <= 11 && !empty($arrConRows[$k] -> OneStake)){
					$WagerNo = round($Rows -> MemStake / $arrConRows[$k] -> OneStake);
					if($WagerNo > 1){
						$strTmp = '<span class="WagerCon_WagerNo_color">'.$arrConRows[$k] -> OneStake.' x '.$WagerNo.'</span><br /><br />';
					}
				}
				$tmpBetList = str_replace("{Show_MemStake}", $strTmp.sprintf("%.1f", $Rows -> MemStake), $tmpBetList);
				if($Rows -> isPayOff < 0){
					$tmpBetList = str_replace("{Show_SubIncome}", "<a style='color: #FF0000'>Cancel</a>", $tmpBetList);
				}else{
					$tmpBetList = str_replace("{Show_SubIncome}", sprintf("%.1f", $Rows -> SubIncome), $tmpBetList);
					$sumtotals ++;
					$sumMemStake += $Rows -> MemStake;
					$sumSubIncome += $Rows -> SubIncome;
				}

				$strBetList .= $tmpBetList;
			}
		}
		@mysql_free_result();
	}
	$fp = ereg_replace("<!--@ BetList Start @//-->.+<!--@ BetList End @//-->", $strBetList, $fp);

	$fp = str_replace("{SumTotals}", number_format($sumtotals), $fp);
	$fp = str_replace("{SumMemStake}", sprintf("%.1f",$sumMemStake), $fp);
	$fp = str_replace("{SumSubIncome}", sprintf("%.1f",$sumSubIncome), $fp);

	if($_data["Types"] == "Stock"){
		$fp = str_replace("{Show_SubAccount}", $_data["SubAccount"], $fp);
		$fp = str_replace("{Sub_Nos}", number_format($Sub_Nos), $fp);
		$fp = str_replace("{Sub_MS}", sprintf("%.1f",$Sub_MS), $fp);
		$fp = str_replace("{Sub_SR}", sprintf("%.1f",$Sub_SR), $fp);
	}else{
		$fp = ereg_replace("<!--@ ShowAgent Start @//-->.+<!--@ ShowAgent End @//-->", "", $fp);
	}

	print $fp;
?>